<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>企业备案信息</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <style type="text/css">
        .popover {
            max-width: 500px;
            width: auto;
        }
    </style>


    <c:if test="${'insert' eq operType}">
        <c:set var="isEditablePageCust" value="true"></c:set>
        <c:set var="isEditablePageInsp" value="true"></c:set>
    </c:if>
    <c:if test="${'view' eq operType}">
        <c:set var="isEditablePageCust" value="false"></c:set>
        <c:set var="isEditablePageInsp" value="false"></c:set>
    </c:if>
    <c:if test="${'edit' eq operType}">
        <c:set var="isEditablePageCust" value="false"></c:set>

        <c:set var="isEditablePageInsp" value="false"></c:set>
        <c:if test="${empty insp.status || 'E1' eq insp.status || '1' eq insp.status || '4' eq insp.status || '9' eq insp.status}">
            <c:set var="isEditablePageInsp" value="true"></c:set>
        </c:if>
    </c:if>
</head>
<body style="border: 20px;overflow: auto">
<ui:custParamQry></ui:custParamQry>
<div>
    <div class="row-fluid box">
        <div class="span12">
            <div class="page-header">
                <div style="float:left">
                    <h1 class="pull-left">
                        <i class="icon-list-ul"></i>
                        <span>海关备案</span>
                    </h1>
                </div>
                <div class="div-status-display">
                    <span><i class="icon-bookmark text-red"></i>状态: </span>
                    <span>
                        ${empty cust.statusDisplay ? '暂无' : cust.statusDisplay}
                    </span>
                </div>
                <div style="float: right;margin-top: 10px">
                    <c:if test="${isEditablePageCust}">
                        <button class="btn btn-primary btn-small" id="readCustCardBtn">
                            <i class="icon-download"></i>读海关法人卡
                        </button>
                        <button class="btn btn-primary btn-small" id="saveCustEntbackupBtn">
                            <i class="icon-save"></i>备案
                        </button>
                    </c:if>

                    <button class="btn btn-primary btn-small"
                            onclick="javascript:history.go(-1)">
                        <i class="fa fa-reply"></i>返回
                    </button>
                </div>
            </div>

        </div>
        <div class="span12 box-content">
            <form id="custBackupForm">
                <input type="hidden" name="id" value="${cust.id}">
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            IC卡号
                        </td>
                        <td class="tdCss">
                            <input type="text" name="icId" readonly="readonly"
                                   value="${cust.icId}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            企业中文名称
                        </td>
                        <td class="tdCss">
                            <input type="text" name="entNameCn" readonly="readonly"
                                   value="${cust.entNameCn}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            组织结构代码
                        </td>
                        <td class="tdCss">
                            <input type="text" name="entOrgCode" readonly="readonly"
                                   value="${cust.entOrgCode}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            企业海关十位
                        </td>
                        <td class="tdCss">
                            <input type="text" name="customsId" readonly="readonly"
                                   value="${cust.customsId}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            操作员姓名
                        </td>
                        <td class="tdCss">
                            <input type="text" name="operator" readonly="readonly"
                                   value="${cust.operator}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            报关员注册编号
                        </td>
                        <td class="tdCss">
                            <input type="text" name="declaretorId" readonly="readonly"
                                   value="${cust.declaretorId}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            IC卡证书信息
                        </td>
                        <td class="tdCss">
                            <input type="text" name="icCaInfo" readonly="readonly"
                                   value="${cust.icCaInfo}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            备案时间
                        </td>
                        <td class="tdCss">
                            <input type="text" name="backupTime"  readonly="readonly"
                                   value="${cust.backupTime}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            </form>
        </div>
    </div>

    <div class="row-fluid box">
        <div class="span12">
            <div class="page-header">
                <div style="float:left">
                    <h1 class="pull-left">
                        <i class="icon-list-ul"></i>
                        <span>检验检疫备案</span>
                    </h1>
                </div>
                <div class="div-status-display">
                    <span><i class="icon-bookmark text-blue"></i>状态: </span>
                    <span style="cursor: pointer" id="inspStatusDisplay">
                        ${empty insp.statusDisplay ? '暂无' : insp.statusDisplay}
                    </span>
                </div>
                <div style="float: right;margin-top: 10px">
                    <c:if test="${isEditablePageInsp}">
                        <button class="btn btn-primary btn-small" id="getInspBackupBtn">
                            <i class="icon-download"></i>获取检已备案信息
                        </button>
                        <button class="btn btn-primary btn-small" id="saveInspEntbackupBtn">
                            <i class="icon-save"></i>保存
                        </button>
                        <button class="btn btn-primary btn-small" id="declareInspEntbackupBtn">
                            <i class="icon-save"></i>备案
                        </button>

                    </c:if>
                </div>
            </div>

        </div>
</div>
        <div class="row-fluid box">
        <div class="title">
            <i class="icon-edit" style="color: #00F;">
            </i>
            <strong>基本信息</strong>
        </div>
        <div class="span12 box-content">
            <form id="inspBackupForm">
                <input type="hidden" name="id" value="${insp.id}">
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            企业备案流水号
                        </td>
                        <td class="tdCss">
                            <input type="text" name="entserialno" readonly="readonly"
                                   value="${insp.entserialno}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            企业中文名
                        </td>
                        <td class="tdCss">
                            <input type="text" name="entcname" readonly="readonly"
                                   value="${insp.entcname}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
                <div class="span4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr>
                            <td class="titleCss100">
                                社会信用代码
                            </td>
                            <td class="tdCss">
                                <input type="text" name="orgno" readonly="readonly"
                                       value="${insp.orgno}">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="span4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr>
                            <td class="titleCss100">
                                企业类型
                            </td>
                            <td class="tdCss">
                                <c:forEach var="item" items="${func:dictGroup('inspCompanyType')}">
                                    <c:set var="inspChecked" value=""/>
                                    <c:if test="${'pl' eq item.itemKey && 'Y' eq insp.enttypepl}">
                                        <c:set var="inspChecked" value="checked"/>
                                    </c:if>
                                    <c:if test="${'cbe' eq item.itemKey && 'Y' eq insp.enttypecbe}">
                                        <c:set var="inspChecked" value="checked"/>
                                    </c:if>
                                    <c:if test="${'lst' eq item.itemKey && 'Y' eq insp.enttypelst}">
                                        <c:set var="inspChecked" value="checked"/>
                                    </c:if>
                                    <c:if test="${'ot' eq item.itemKey && 'Y' eq insp.enttypeot}">
                                        <c:set var="inspChecked" value="checked"/>
                                    </c:if>
                                    <label class="checkbox" style="float: left; font-size: 12px">
                                        <input type="checkbox" id="_enttype${item.itemKey}" name="enttype" ${inspChecked}
                                               value="${item.itemKey}" onchange="checkEntType(this)"/>${item.itemValue}</label>
                                        <input type="hidden" name="enttype${item.itemKey}" value="${inspChecked eq 'checked' ? 'Y' : 'N'}">
                                    <script type="text/javascript">
                                        function checkEntType(obj)
                                        {
                                            $("input[name='enttype"+obj.value+"']").val(obj.checked ? "Y" : "N");
                                        }
                                    </script>
                                </c:forEach>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            属地检机构代码
                        </td>
                        <td class="tdCss">
                            <ui:tsingletableautocomplete
                                    keyFieldName="ciqorgtypecode"
                                    valueFieldName="ciqorgtypecodexxxx"
                                    tableName="S_Bbd_Organize"
                                    key="ORG_CODE"
                                    value="ORG_CNAME"
                                    relateKeyFieldName=""
                                    relateValueFieldName=""
                                    defaultKey="${insp.ciqorgtypecode}"
                                    defaultValue=""/>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            注册地址
                        </td>
                        <td class="tdCss">
                            <input type="text" name="registeraddress"
                                   value="${insp.registeraddress}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            法定代表人
                        </td>
                        <td class="tdCss">
                            <input type="text" name="lawman"
                                   value="${insp.lawman}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            单位联系人
                        </td>
                        <td class="tdCss">
                            <input type="text" name="contactman"
                                   value="${insp.contactman}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            单位联系人手机
                        </td>
                        <td class="tdCss">
                            <input type="text" name="contactmanmobile"
                                   value="${insp.contactmanmobile}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <td class="titleCss100">
                            备案时间
                        </td>
                        <td class="tdCss">
                            <input type="text" name="applytime" readonly="readonly"
                                   value="${insp.applytime}">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
                <div class="span4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr>
                            <td class="titleCss100">
                                备案号
                            </td>
                            <td class="tdCss">
                                <input type="text" name="backupNo" readonly="readonly"
                                       value="${insp.backupNo}">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
</div>

        <div class="row-fluid box">
            <div class="span12 box-header">
                <div class="title">
                    <i class="icon-edit" style="color: #00F;">
                    </i>
                    <strong>附件信息</strong>
                </div>
            </div>
            <div class="span12">
                <div class='responsive-table' style="padding-left: 5px;">
                    <table id="attachList">
                    </table>
                    <div id="attachListPaper">
                    </div>
                </div>

            </div>
            <c:if test="${isEditablePageInsp}">
                <div class="span12  box-header">
                    <div style="float: right">
                        <button class="btn btn-primary btn-small" id="attach_save_btn">
                            <i class="icon-save"></i>保存
                        </button>
                        <button class="btn btn-primary btn-small" id="attach_delete_btn">
                            <i class="icon-save"></i>删除
                        </button>
                    </div>
                </div>

                <div class="span12 box box-content" id="attachEditDiv">
                    <jsp:include page="/WEB-INF/pages/entBackup/edit_attach.jsp" flush="true"/>
                </div>
            </c:if>
        </div>

        <div class="row-fluid box">
            <div class="span12 box-header">
                <div class="title">
                    <i class="icon-edit" style="color: #00F;">
                    </i>
                    <strong>网址信息</strong>
                </div>
            </div>
            <div class="span12">
                <div class='responsive-table' style="padding-left: 5px;">
                    <table id="websiteList">
                    </table>
                    <div id="websiteListPaper">
                    </div>
                </div>
            </div>
            <c:if test="${isEditablePageInsp}">
                <div class="span12  box-header">
                    <div style="float: right">
                        <button class="btn btn-primary btn-small" id="website_save_btn">
                            <i class="icon-save"></i>保存
                        </button>
                        <button class="btn btn-primary btn-small" id="website_delete_btn">
                            <i class="icon-save"></i>删除
                        </button>
                    </div>
                </div>
                <div class="span12 box box-content" id="websiteEditDiv">
                    <jsp:include page="/WEB-INF/pages/entBackup/edit_website.jsp" flush="true"/>
                </div>
            </c:if>
        </div>
    </div>

</div>
</body>
<script type="text/javascript">

    function initAttachList() {
        $("#attachList").jqGrid({
            datatype: "json",
            url: $basePath + "/entBackup/pageAttach",
            postData: {"relateId": $("#inspBackupForm input[name='id']").val()}, //发送数据
            colNames: ['流水号',
                '文件名',
                '附件类型',
                '备注',
                '入库时间',
                ''
            ],
            colModel: [{name: 'id', index: 'id', hidden: true},
                {name: 'annexname', index: 'annexname',formatter: function (cellvalue, options, rowObject) {
                    return "<a class='btn-link' href='#download' onclick=\"fileDownload('" + rowObject.fileId + "')\"><span style='color:#00acec'>" + rowObject.annexname + "</span></a>"
                }},
                {name: 'annextypeDisplay', index: 'annextypeDisplay'},
                {name: 'remark', index: 'remark'},
                {name: 'createTime', index: 'createTime'},
                {name: 'fileId', index: 'fileId', hidden:true}
            ],
            height: 'auto',
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 5, //每页显示记录数
            rowList: [5, 10, 20], //可调整每页显示的记录数
//            rownumbers: true,
            multiselect: ${isEditablePageInsp}, //是否支持多选
            multiselectWidth: 35,
            viewrecords: true, //是否显示行数
            pager: "#attachListPaper", //分页工具栏
            altRows: true,
            altclass: 'someClass',
            sortable: true,
            sortname: 'createTime',
            sortorder: 'asc',
            width: $('body').width(),
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                } else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $("#" + this.id).setGridWidth($(".responsive-table").parent().width() * 0.98);
                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
                $("body").height($("body").height() + $(".responsive-table:eq(1)").height() + 50);
            }
        });
    }

    function queryWebsite(cellvalue, options, rowObject) {
        var isView = ${'view' eq operType};
        if (isView) {
            return cellvalue;
        }
        var url = '${basePath}/entBackup/queryWebsite?applicationIdZ=' + rowObject['applicationIdZ'];
        return "<a class='btn-link' data-value='" + cellvalue + "' onclick='loadDiv(\"websiteEditDiv\",\"" + url + "\");return false;'>" + "<span style='color:#00acec'>" + cellvalue + "</span></a>";
    }
    function initWebsiteList() {
        $("#websiteList").jqGrid({
            datatype: "json",
            url: $basePath + "/entBackup/pageWebsite",
            postData: {"relateId": $("#inspBackupForm input[name='id']").val()}, //发送数据
            colNames: [
                '流水号',
                '网址',
                '网站名',
                '经营商品',
                '入库时间'
            ],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'url', index: 'url', width: '200px'},
                {name: 'sitename', index: 'siteName', width: '250px'},
                {name: 'busscope', index: 'busScope', width: '250px'},
                {name: 'createTime', index: 'createTime', width: '150px'}

            ],
            height: 'auto',
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 5, //每页显示记录数
            rowList: [5, 10, 20], //可调整每页显示的记录数
//            rownumbers: true,
            multiselect: true, //是否支持多选
            multiselectWidth: 35,
            viewrecords: true, //是否显示行数
            pager: "#websiteListPaper", //分页工具栏
            altRows: true,
            altclass: 'someClass',
            sortable: true,
            sortname: 'createTime',
            sortorder: 'desc',
            width: $('body').width(),

            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                } else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });
    }

    function getSelectIDs(gridId) {
        var selectIDs = $("#" + gridId + "").getGridParam("selarrrow");
        var rows = [];
        for (var rowId in selectIDs) {
            var _row = $("#" + gridId + "").jqGrid("getRowData", selectIDs[rowId]);
            rows.push(_row.id);
        }

        return rows;
    }

    var isReadCard = false;
    function initBindBtnEvent() {
        var isView = ${'view' eq operType};
        if (isView) {
            return;
        }

        $("#readCustCardBtn").bind("click", function () {
            isReadCard = false;
            $("#custBackupForm input").val('');

            var custCardInfo = getIcUserInfo();
//            {'icId':'icId', 'entNameCn':'entNameCn','entOrgCode':'entOrgCode',
//                    'customsId':'customsId','operator':'operator','declaretorId':'declaretorId','icCaInfo':'icCaInfo'
//            };
            if (custCardInfo) {
                $("#custBackupForm input[name='icId']").val(custCardInfo['icId']);
                $("#custBackupForm input[name='entNameCn']").val(custCardInfo['entNameCn']);
                $("#custBackupForm input[name='entOrgCode']").val(custCardInfo['entOrgCode']);
                $("#custBackupForm input[name='customsId']").val(custCardInfo['customsId']);
                $("#custBackupForm input[name='operator']").val(custCardInfo['operator']);
                $("#custBackupForm input[name='declaretorId']").val(custCardInfo['declaretorId']);
                $("#custBackupForm input[name='icCaInfo']").val(custCardInfo['icCaInfo']);
                isReadCard = true;
            }
        });
        $("#saveCustEntbackupBtn").bind("click", function () {
            if(!isReadCard)
            {
                layerAlert("请先读取海关企业法人卡");
                return;
            }

            if ($("#custBackupForm input[name='customsId']").val() == '') {
                layerAlert("获取不到海关十位编码！");
                return;
            }

            $.post("${basePath}/entBackup/saveHeadCust",
                    $("#custBackupForm input").serialize(),
                    function (result) {
                        if (result['code'] + '' == '1') {
                            layerAlertOk("备案成功！", function(){
                                location.href = "${basePath}/entBackup/edit?id="+result['msg']+"&r=" + Math.random();
                            });
                            return;
                        }

                        layerAlert("备案失败," + result['msg']);
                    },
                    'JSON').error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });
        $("#getInspBackupBtn").bind("click", function () {

            var _orgno = $("#inspBackupForm input[name='orgno']").val();
            if( _orgno== '')
            {
                layerAlert("请先进行海关备案");
                return;
            }

            layerAlert("组织机构代码:" + _orgno+ "获取不到检验检验已备案信息");
        });
        $("#saveInspEntbackupBtn").bind("click", function () {

            var _orgno = $("#inspBackupForm input[name='orgno']").val();
            if( _orgno== '')
            {
                layerAlert("请先进行海关备案");
                return;
            }

            if(!isValid("inspBackupForm"))
            {
                return;
            }
            $.post("${basePath}/entBackup/saveHeadInsp",
                    $("#inspBackupForm input").serialize(),
                    function (result) {
                        if (result['code'] + '' == '1') {
                            layerAlertOk("保存成功！", function(){
                                location.href = "${basePath}/entBackup/edit?id="+result['msg']+"&r=" + Math.random();
                            });
                            return;
                        }

                        layerAlert("保存失败," + result['msg']);
                    },
                    'JSON').error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });

        $("#declareInspEntbackupBtn").bind("click", function () {

            var _orgno = $("#inspBackupForm input[name='orgno']").val();
            if( _orgno== '')
            {
                layerAlert("请先进行海关备案");
                return;
            }

            if(!isValid("inspBackupForm"))
            {
                return;
            }
            $.post("${basePath}/entBackup/declareInsp",
                    $("#inspBackupForm input").serialize(),
                    function (result) {
                        if (result['code'] + '' == '1') {
                            layerAlertOk("备案数据提交申请成功！", function(){
                                location.href = "${basePath}/entBackup/edit?id="+result['msg']+"&r=" + Math.random();
                            });
                            return;
                        }

                        layerAlert("备案数据提交申请失败," + result['msg']);
                    },
                    'JSON').error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });

        $("#attach_save_btn").bind("click", function () {

            var _orgno = $("#inspBackupForm input[name='orgno']").val();
            if( _orgno== '')
            {
                layerAlert("请先进行海关备案");
                return;
            }

            if ($("#inspBackupForm input[name='id']").val() == '') {
                layerAlert("请先保存基本信息！");
                return;
            }
            if (!isValid('attach')) {
                return;
            }

            $.post("${basePath}/entBackup/saveAttach",
                    "relateId=" + $("#inspBackupForm input[name='id']").val()
                    + "&" + $("#attachEditDiv input,textarea").serialize(),
                    function () {
                        layerAlertOk("保存成功",  function () {
                            $("#attachList").jqGrid('setGridParam', {url: $basePath + "/entBackup/pageAttach" })
                                    .trigger("reloadGrid");
                            $("#attach input,textarea").val('');

                        });
                    }).error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });
        $("#attach_delete_btn").bind("click", function () {
            var selectIDs = getSelectIDs('attachList');
            if (selectIDs.length < 1) {
                layerAlert("对不起,您没有选中任何记录");
                return;
            }

            var _data = "id=" + selectIDs.join("&id=").toString();
            showConfirm("确定要删除选中的记录吗?", "系统提示", function () {

                $.ajax({
                    type: "post",
                    url: '${basePath}/entBackup/deleteAttach',
                    data: _data,
                    success: function () {
                        layerAlertOk('删除成功!', function () {
                            $("#attachList").jqGrid('setGridParam', {url: $basePath + "/entBackup/pageAttach"})
                                    .trigger("reloadGrid");
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layerAlert("系统繁忙,保存失败");
                    }
                });
            });
        });
        $("#website_save_btn").bind("click", function () {
            var _orgno = $("#inspBackupForm input[name='orgno']").val();
            if( _orgno== '')
            {
                layerAlert("请先进行海关备案");
                return;
            }
            if ($("#inspBackupForm input[name='id']").val() == '') {
                layerAlert("请先保存基本信息！");
                return;
            }
            if (!isValid('site')) {
                return;
            }

            $.post("${basePath}/entBackup/saveWebsite",
                    "relateId=" + $("#inspBackupForm input[name='id']").val()
                    + "&" + $("#websiteEditDiv input").serialize(),
                    function () {
                        layerAlertOk("保存成功", function () {
                            $('#websiteEditDiv input').val('');
                            $("#websiteList").jqGrid('setGridParam', {url: $basePath + "/entBackup/pageWebsite" })
                                    .trigger("reloadGrid");
                        });
                    }).error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });
        $("#website_delete_btn").bind("click", function () {
            var selectIDs = getSelectIDs('websiteList');
            if (selectIDs.length < 1) {
                layerAlert("对不起,您没有选中任何记录");
                return;
            }

            var _data = "id=" + selectIDs.join("&id=").toString();
            showConfirm("确定要删除选中的记录吗?", "系统提示", function () {

                $.ajax({
                    type: "post",
                    url: '${basePath}/entBackup/deleteWebsite',
                    data: _data,
                    success: function () {
                        layerAlertOk('删除成功!', function () {
                            $('#websiteEditDiv input').val('');
                            $("#websiteList").jqGrid('setGridParam', {url: $basePath + "/entBackup/pageWebsite"})
                                    .trigger("reloadGrid");
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layerAlert("系统繁忙,保存失败");
                    }
                });
            });
        });

    }

    function disabledPage() {
        if (!${isEditablePageCust}) {
            $("#custBackupForm input,textarea").attr("disabled", true);
            $("#custBackupForm a").attr("disabled", "disabled").attr("href", 'javascript:void(0)').unbind('click').attr("onclick", function () {
            });
        }

        if (!${isEditablePageInsp}) {
            $("#inspBackupForm input,textarea").attr("disabled", true);
            $("#inspBackupForm a").attr("disabled", "disabled").attr("href", 'javascript:void(0)').unbind('click').attr("onclick", function () {
            });
        }
    }

    function initValid()
    {
        var rules = {
            icId : {minlength:1},
            entNameCn : {minlength:1},
            entOrgCode : {minlength:1},
            customsId : {minlength:1},
            operator : {minlength:1}
        };
        formValidate("custBackupForm", rules, true);

        rules = {
            entserialno : {minlength:1},
            entcname : {minlength:1},
            orgno : {minlength:1},
            enttype : {minlength:1},
            ciqorgtypecode : {minlength:1},
            registeraddress : {minlength:1, maxlength:150},
            lawman : {minlength:1, maxlength:500},
            contactman: {minlength:1, maxlength:50},
            contactmanmobile:{minlength:1, maxlength:50}
        };
        formValidate("inspBackupForm", rules, true);
    }

    function initStatus()
    {
        popStatus("inspStatusDisplay",
                "${basePath}/status/getInspStatus",
                {"receiptNo": $("#inspBackupForm input[name='entserialno']").val(),
                 "statusGroupId" : "DEC_STATUS_ENT_INSP"
                }
        );
    }

    $(function () {
        initStatus();
        initAttachList();
        initWebsiteList();
        initBindBtnEvent();
        initValid();
        disabledPage();
    });
</script>

</html>
